package com.zsk.cxf.service;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.zsk.cxf.service.bean.FileParam;
import com.zsk.cxf.service.bean.UserParam;

/**
 * 官方文档：https://cxf.apache.org/docs/jax-rs-multiparts.html
 * 
 * @author keke
 * @date   2021/01/25
 */
public interface IDemoService {

    /**
     * path传参：http://127.0.0.1:8080/cxf/demo/user/1
     * 
     * @param  id
     * @return
     */
    @GET
    @Path("/user/{id}")
    @Consumes({MediaType.APPLICATION_JSON})
    @Produces({MediaType.APPLICATION_JSON})
    UserParam getUser(@PathParam("id") String id);

    /**
     * query传参：http://127.0.0.1:8080/cxf/demo/user?id=1&name=zhangsan
     * 
     * @param  id
     * @param  name
     * @return
     */
    @GET
    @Path("/user")
    String getUsers(@QueryParam("id") String id, @QueryParam("name") String name);

    /**
     * 表单提交自动绑定对象：age: 12222 name: zhangsike sex: true <br>
     * 绑对象时@FormParam("")传""
     * 
     * @param  user
     * @return
     */
    @POST
    @Path("/add/user")
    @Consumes("multipart/form-data")
    @Produces(MediaType.APPLICATION_JSON)
    UserParam postForm(@FormParam("") UserParam user);

    /**
     * 表单提交绑定对象绑定key中带点的特殊值<br>
     * age: 12222 name: zhangsike sex: true fileName: sadasd length: 32323 a.b: zhasdasd
     * 
     * @param  age
     * @param  name
     * @param  fileInfo
     * @return
     */
    @POST
    @Path("/add/user2")
    @Consumes("multipart/form-data")
    @Produces(MediaType.APPLICATION_JSON)
    UserParam postUser(@FormParam("a.b") String ab, 
        @FormParam("age") int age, 
        @FormParam("name") String name,
        @FormParam("") FileParam fileInfo 
    );
}
